Function line(s As String)
	k = InStr(s, "*")
	s1 = Right(s, (Len(s) - k))
	k1 = InStr(s1, "*")
	s2 = Right(s1, (Len(s1) - k1))
	k2 = InStr(s2, "*")
	s3 = Left(s2, (k2 - 1))
	line = Val(s3)
End Function

Function rollwidth(s As String)
'复卷方案中复卷规格宽幅
	k = InStr(s, "*")
	s1 = Right(s, Len(s) - k)
	k1 = InStr(s1, "*")

	muti = Val(Left(s, k - 1))
	roll = Val(Left(s1, k1 - 1))
	rollwidth = muti * roll
End Function

Function getzb(mother, Optional ByVal column_divideroll = 7)
'mother is mother roll
'column_divideroll is the column of divided roll

	motherrows = mother.MergeArea.Rows.Count
	getzb = mother.value
	If getzb = 0 Then
		etzb = ""
	Else
		For i = 0 To motherrows - 1
		getzb = getzb - rollwidth(Cells(mother.Row() + i, column_divideroll).value)
		Next i
	End If
End Function

Function getts(g, a, s As String, m)
	If g = 0 Then
		getts = ""
	Else
		ts_per = a / 1000 * g * line(s) / 1000000
		getts = m / ts_per
	End If
End Function

Function cal(pz As String, g, a, s As String, m)  '品种，克重，母卷宽幅，规格，复卷量
If g = 0 Then cal = 0
If g > 0 Then
b = line(s)            '规格中的线长
If (pz = "AIV") Or (pz = "IV2") Or (pz = "IV3") Then pz = "FIV"
If (pz = "IV1") Or (pz = "IVS") Then pz = "FIV"
If pz = "SB0" Then pz = "SBS"
If (Left(pz, 2) = "PC") Then pz = "PC"
Select Case pz

'PM4 MAIN --------------------------------------------
Case "SBS"
    Select Case g
    Case 215
    n = 153
    Case 220
    n = 170
    Case 225
    n = 188
    Case 230
    n = 193
   End Select
Case "FIV"
    Select Case g
    Case 170
    b0 = 15400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 171.7
       Case 3
       n = 155.7
       End Select
    Case 190
    b0 = 13000   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 157.4
       Case 3
       n = 174.9
       End Select
    Case 210
    b0 = 11500   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 180
       Case 3
       n = 161
       End Select
       
       '烟包一套
       Case 215
       n = 153
       
     Case 225
       n = 188
     Case 230
     b0 = 10600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 187.5
       Case 3
       n = 167.4
       End Select
     Case 250
      b0 = 9400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 188.9
       Case 3
       n = 167.8
       End Select
     
     Case 270
      b0 = 8200   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 186.4
       Case 3
       n = 164.7
       End Select
     Case 300
       b0 = 7600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 196.6 + 10   '300G修正
       Case 3
       n = 173.2 + 10
       End Select
    
    
     Case 300
       b0 = 7600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 196.6 + 10   '300G修正
       Case 3
       n = 173.2 + 10
       
       End Select
       
    Case 325
       b0 = 6900   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 199 + 10   '300G修正
       Case 3
       n = 175 + 10
       
       End Select
    
    Case 350
        b0 = 6400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 203 + 8
       Case 3
       n = 177.7 + 8
       End Select
    Case 400
       b0 = 5800   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 215.7
       Case 3
       n = 188.3
       End Select
End Select
'PM4 MAIN------------------------------------------------------

Case "DIV"
    Select Case g
    Case 220 To 270
    n = 180
    Case 300 To 325
    n = 195
    Case 350
    n = 204
    Case 400 To 440
    n = 215
    End Select
Case "GAB"
n = 230
Case "PC"
b0 = 11000                '母卷线长
t = Int(b0 / b)            '套数
    Select Case t
    Case 2
    n = 210
    Case 3
    n = 190
    End Select
Case "DC1"
    Select Case g
    Case 400
    n = 232
    Case 350
    n = 215
    Case 300
    n = 202
    Case 250
    b0 = 10000
    t = Int(b0 / b)
        Select Case t
        Case 2
        n = 190
        Case 3
        n = 165
        Case 4
        n = 150
        End Select
    End Select
Case "UIV"
n = 180
Case ""
m = 0
a = 1
n = 1
End Select
cal = m * 3300 / a * 180 / n
End If
If cal = 0 Then cal = ""
'PM6 烟包速度修正40%
If pz = "SBS" Then cal = cal / 0.4

End Function

Function calpm6(pz As String, g, a, s As String, m)  '品种，克重，母卷宽幅，规格，复卷量
If g = 0 Then calpm6 = 0
If g > 0 Then
b = line(s)            '规格中的线长
If (pz = "AIV") Or (pz = "IV2") Or (pz = "IV3") Then pz = "DIV"
If (pz = "IV1") Then pz = "FIV"
If (pz = "SB0") Or (pz = "IVS") Then pz = "SBS"
If (Left(pz, 2) = "PC") Then pz = "PC"
If pz = "UAB" Then pz = "GAB"
Select Case pz

Case "DIV"
    Select Case g
    Case 220 To 270
    n = 180
    Case 300 To 325
    n = 195
    Case 350
    n = 204
    Case 400 To 440
    n = 215
    End Select
Case "GAB"
n = 230
Case "PC"
b0 = 11000                '母卷线长
t = Int(b0 / b)            '套数
    Select Case t
    Case 2
    n = 210
    Case 3
    n = 190
    End Select
Case "DC1"
    Select Case g
    Case 400
    n = 232
    Case 350
    n = 215
    Case 300
    n = 202
    Case 250
    b0 = 10000
    t = Int(b0 / b)
        Select Case t
        Case 2
        n = 190
        Case 3
        n = 165
        Case 4
        n = 150
        End Select
    End Select
Case "UIV"
n = 180

'PM4 MAIN --------------------------------------------
Case "SBS"
    Select Case g
    Case 215
    n = 153
    Case 220
    n = 170
    Case 225
    n = 188
    Case 230
    n = 193
   End Select
Case "FIV"
    Select Case g
    Case 170
    b0 = 15400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 171.7
       Case 3
       n = 155.7
       End Select
    Case 190
    b0 = 13000   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 157.4
       Case 3
       n = 174.9
       End Select
    Case 210
    b0 = 11500   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 180
       Case 3
       n = 161
       End Select
       
       '烟包一套
       Case 215
       n = 153
       
     Case 225
       n = 188
     Case 230
     b0 = 10600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 187.5
       Case 3
       n = 167.4
       End Select
     Case 250
      b0 = 9400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 188.9
       Case 3
       n = 167.8
       End Select
     
     Case 270
      b0 = 8200   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 186.4
       Case 3
       n = 164.7
       End Select
     Case 300
       b0 = 7600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 196.6 + 10   '300G修正
       Case 3
       n = 173.2 + 10
       End Select
    
    
     Case 300
       b0 = 7600   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 196.6 + 10   '300G修正
       Case 3
       n = 173.2 + 10
       
       End Select
       
    Case 325
       b0 = 6900   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 199 + 10   '300G修正
       Case 3
       n = 175 + 10
       
       End Select
    
    Case 350
        b0 = 6400   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 203 + 8
       Case 3
       n = 177.7 + 8
       End Select
    Case 400
       b0 = 5800   '母卷线长
    t = Int(b0 / b)   '套数
       Select Case t
       Case 2
       n = 215.7
       Case 3
       n = 188.3
       End Select
End Select
'PM4 MAIN------------------------------------------------------

Case ""
m = 0
a = 1
n = 1
End Select
calpm6 = m * 3300 / a * 180 / n
End If
If calpm6 = 0 Then calpm6 = ""
'PM6 烟包速度修正40%
If pz = "SBS" Then calpm6 = calpm6 / 0.4
If pz = "PC" Then calpm6 = calpm6 / 0.7


End Function


